<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item v-if="showMs">
          <el-select
            v-model="dataForm.islandId"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.scenicName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="showMs">
          <el-select
            v-model="dataForm.homestayId"
            placeholder="关联民宿"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in homestays"
              :key="index"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.queryType"
            placeholder="时间维度"
            clearable
          >
            <el-option :value="0" label="月度"> </el-option>
            <el-option :value="1" label="年度"> </el-option>
          </el-select>
        </el-form-item>
        <template v-if="dataForm.queryType == 0">
          <el-form-item>
            <el-date-picker
              v-model="dataForm.startDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="到达时间"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="dataForm.endDate"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="离开时间"
            >
            </el-date-picker>
          </el-form-item>
        </template>
        <template v-if="dataForm.queryType == 1">
          <el-date-picker
            v-model="dataForm.annualDate"
            value-format="yyyy"
            type="year"
            placeholder="选择年"
          >
          </el-date-picker>
        </template>
        <el-form-item style="margin-left: 10px">
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('hotel:report:turnover')" type="primary" @click="exportHandle()">导出</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        height="calc(100vh - 250px)"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="islandName"
          label="所属区域"
          header-align="center"
          min-width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="homestayName"
          label="所属酒店民宿"
          header-align="center"
          min-width="180"
          align="center"
        ></el-table-column>
        <!-- <el-table-column prop="statisticsDate" label="统计日期" header-align="center" min-width="150" align="center"></el-table-column> -->
        <el-table-column
          prop="turnover"
          sortable="custom"
          label="营业额"
          header-align="center"
          min-width="150"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="saleRooms"
          label="出售客房数"
          sortable="custom"
          header-align="center"
          align="center"
          min-width="150"
        ></el-table-column>
        <el-table-column
          prop="checkInRatio"
          label="入住率(%)"
          min-width="150"
          sortable="custom"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="roomPrice"
          label="房费(元)"
          sortable="custom"
          header-align="center"
          align="center"
          min-width="150"
        ></el-table-column>
        <el-table-column
          prop="avgRoomPrice"
          label="平均房价(元)"
          header-align="center"
          align="center"
          min-width="150"
        ></el-table-column>
        <el-table-column
          prop="avgYield"
          label="平均客房收益(元)"
          header-align="center"
          align="center"
          min-width="150"
        ></el-table-column>
        <el-table-column
          prop="orderNums"
          label="订单数量"
          header-align="center"
          align="center"
          min-width="150"
        >
        </el-table-column>
      </el-table>
      <!-- <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination> -->
    </div>
  </el-card>
</template>

<script>
var that;
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/hotel/report/getTurnoverCountList",
        getDataListIsPage: false,
        exportURL: "/hotel/report/exportTurnover",
      },
      homestays: [],
      showMs: false,
      scenicOptions: [],
      dataForm: {
        islandId: "",
        homestayId: this.$store.state.user.homestayId || "",
        annualDate: new Date().getFullYear() + "",
        endDate: "",
        queryType: 1,
        startDate: "",
      },
    };
  },
  watch: {
    "dataForm.queryType"(newval, oldval) {
      if (newval == 0) {
        this.dataForm.annualDate = "";
      } else {
        this.dataForm.startDate = "";
        this.dataForm.endDate = "";
      }
    },
  },
  created() {
    that = this;
    this.getHomestay();
    this.getScenicOptions();
    if (
      this.$store.state.user.roleList &&
      this.$store.state.user.roleList.indexOf("1712742759269081090") > -1
    ) {
      this.showMs = true;
    }
  },
  methods: {
    getHomestay() {
      this.$http
        .get("/hotel/homestay/getHomestayDownBox")
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.homestays = res.data;
          }
        });
    },
    //岛屿
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            this.scenicOptions = res.data;
          }
        });
    },
  },
};
</script>
